package org.begincode.admin.control;

import com.begincode.common.constant.Constant;
import com.begincode.common.util.ResultUtil;
import org.begincode.admin.service.CourseService;
import org.begincode.core.model.Course;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;

/**
 * Created by yangsj on 2016/5/3.
 * 教程
 */
@Controller
@RequestMapping("course")
public class CourseController {
    Logger logger = LoggerFactory.getLogger(CourseController.class);
    @Resource
    private CourseService courseService;

    /**
     * 创建课程
     * */
    @ResponseBody
    @RequestMapping(value = "",method = RequestMethod.POST)
    public Object course(Course course){
        course.setDeleteFlag(Constant.NO_DEL_FLAG);
        int returnValue = courseService.addCourse(course);
        if(returnValue>0){
            return ResultUtil.buildSuccess();
        }else{
            return ResultUtil.buildFail();
        }
    }
    /**
     *创建课程初始化
     * */
    @RequestMapping(value = "/init",method = RequestMethod.GET)
    public Object init(Model model){
        model.addAttribute("courseLevels",courseService.selCourseLevels());
        model.addAttribute("courseLabels",courseService.selCourseLabels());
        model.addAttribute("courseTypes",courseService.selCourseTypes());
        return "admin/courseEdit";
    }

}
